import request from './request'

// ==================== 推荐系统 API ====================

/**
 * 获取推荐系统概览数据
 * @returns {Promise}
 */
export function getRecommendationOverview() {
  return request({
    url: '/recommendation/api/overview/',
    method: 'get'
  })
}

/**
 * 获取算法性能数据
 * @returns {Promise}
 */
export function getAlgorithmPerformance() {
  // 临时返回模拟数据
  return Promise.resolve({
    success: true,
    code: 200,
    data: [
      {
        name: 'collaborative',
        displayName: '协同过滤',
        precision: 0.85,
        recall: 0.78,
        f1Score: 0.81,
        coverage: 0.82,
        diversity: 0.68,
        novelty: 0.72
      }
    ]
  })
}

/**
 * 获取推荐趋势数据
 * @param {Object} params - 查询参数
 * @param {string} params.timeRange - 时间范围 (7d, 30d, 90d)
 * @returns {Promise}
 */
export function getTrendData(params = {}) {
  // 临时返回模拟数据
  const days = params.timeRange === '7d' ? 7 : params.timeRange === '90d' ? 90 : 30
  const data = []

  for (let i = 0; i < days; i++) {
    const date = new Date()
    date.setDate(date.getDate() - (days - 1 - i))
    data.push({
      date: `${date.getMonth() + 1}-${date.getDate()}`,
      recommendations: Math.floor(Math.random() * 500) + 800,
      clicks: Math.floor(Math.random() * 100) + 80,
      conversions: Math.floor(Math.random() * 30) + 20
    })
  }

  return Promise.resolve({
    success: true,
    code: 200,
    data
  })
}

/**
 * 获取热门推荐产品
 * @param {Object} params - 查询参数
 * @param {string} params.category - 产品类别
 * @returns {Promise}
 */
export function getHotProducts(params = {}) {
  return request({
    url: '/recommendation/api/hot-products/',
    method: 'get',
    params
  })
}

/**
 * 获取用户推荐列表
 * @param {Object} params - 查询参数
 * @param {number} params.page - 页码
 * @param {number} params.pageSize - 每页大小
 * @param {string} params.searchKeyword - 搜索关键词
 * @param {string} params.algorithmFilter - 算法过滤
 * @param {string} params.statusFilter - 状态过滤
 * @returns {Promise}
 */
export function getUserRecommendations(params = {}) {
  return request({
    url: '/recommendation/api/user-recommendations/',
    method: 'get',
    params
  })
}

/**
 * 执行推荐
 * @returns {Promise}
 */
export function runRecommendation() {
  return request({
    url: '/recommendation/api/run-recommendation/',
    method: 'post',
    timeout: 120000 // 设置2分钟超时
  })
}


